<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>JSP生成三角形</title>
</head>
<body>
<form>
    <label for="number">请输入整数</label>
    <%
        String s = request.getParameter("num");
        if (s == null) {
            s = "";
        }
    %>
    <input type="number" min="1" id="number" name="num" value="<%=s%>">
    <input type="submit" value="确认">
</form>
正三角：<br/>
<%
    int num = Integer.parseInt(s.equals("") ? "0" : s);
    for (int i = 0; i < num; i++) {
        for (int j = 0; j < num - i; j++) {
            out.print("&nbsp;");
        }
        for (int k = 0; k <= i * 2; k++) {
            out.print("*");
        }
        out.println("</br>");
    }
%>
倒三角：<br/>
<%
    for (int i = num; i > 0; i--) {
        for (int j = num - i; j > 0; j--) {
            out.print("&nbsp;");
        }
        for (int k = (i * 2) - 1; k > 0; --k) {
            out.print("*");
        }
        out.println("</br>");
    }
%>
</body>
</html>
